package com.lyf.boot.translation.impl;

import cn.hutool.core.util.StrUtil;
import com.lyf.boot.annotation.TranslationType;
import com.lyf.boot.constant.TransConstant;
import com.lyf.boot.core.service.IDictService;
import com.lyf.boot.translation.TranslationInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Luyufan
 * @date 2023/8/16 15:21
 */
@Component
@TranslationType(type = TransConstant.DICT_KEY_TO_VALUE)
public class SysDictTypeTranslation implements TranslationInterface<String> {

    @Autowired(required = false)
    private IDictService dictService;

    @Override
    public String translation(Object key, String other) {
        if (key instanceof String && StrUtil.isNotBlank(other)) {
            return dictService.getSysDictValue(other, key.toString());
        }
        return null;
    }
}
